//
//  CJPictorailImageListViewController.m
//  KaiJing
//
//  Created by lanou on 16/1/12.
//  Copyright © 2016年 HuangZuCui. All rights reserved.
//

#import "CJPictorailImageListViewController.h"
#import "CJPictorialMainImagelistModel.h"
#import "UIImageView+WebCache.h"
#import "iCarousel.h"
@interface CJPictorailImageListViewController () <iCarouselDataSource,iCarouselDelegate>

@property (nonatomic, strong) UILabel *pageLabel; //当前叶


@end

@implementation CJPictorailImageListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor blackColor];

    
    iCarousel *icarousel = [[iCarousel alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    icarousel.dataSource = self;
    icarousel.delegate = self;
    icarousel.type = iCarouselTypeInvertedTimeMachine;
    
    icarousel.pagingEnabled = YES;
    icarousel.scrollOffset = _numOfSize;
    [self.view addSubview:icarousel];
    
    
    //当前页
    _pageLabel = [[UILabel alloc] initWithFrame:CGRectMake((kScreenWidth - 150) / 2, kScreenHeight - 90, 150, 25)];
    _pageLabel.textAlignment = NSTextAlignmentCenter;
    _pageLabel.text = [NSString stringWithFormat:@"%ld / %ld",(long)_numOfSize + 1,(unsigned long)_imageListArray.count];
    _pageLabel.textColor = [UIColor whiteColor];
    [self.view addSubview:_pageLabel];

    //轻拍手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [icarousel.subviews[0] addGestureRecognizer:tap];


}

- (NSInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
    return _imageListArray.count;
}



- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view
{
    CJPictorialMainImagelistModel *model = _imageListArray[index];
    CGFloat width = (CGFloat)[model.width floatValue];
    CGFloat height = (CGFloat)[model.height floatValue];
    UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, height / width * kScreenWidth)];
    [imageV sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://morguo.com/%@",model.thumb]] placeholderImage:[UIImage imageNamed:@"parise"]];
    
    return imageV;
    
    
}

- (void)carouselDidEndScrollingAnimation:(iCarousel *)carousel
{
    NSInteger index = carousel.scrollOffset;
     _pageLabel.text = [NSString stringWithFormat:@"%ld / %ld",index + 1,(unsigned long)_imageListArray.count];
}


- (void)tapAction:(UITapGestureRecognizer *)tap {
    
    

    
    [self dismissViewControllerAnimated:NO completion:nil];
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
